package com.cx.base.day09_utilclass;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

/**
 * @author shkstart
 * @date 7/26/2019 - 10:12 AM
 */
public class Util_01_Date {
    public static void main(String[] args) {

        LocalDateTime ldt = LocalDateTime.now();
        System.out.println(ldt);

        LocalDate ld = LocalDate.now();
        System.out.println(ld);

        Date date = new Date();
        System.out.println(date);
        Date date1 = new Date();
        System.out.println("距离格林尼治时间（ms）:" + date.getTime());
        System.out.println("当前时间：" + date);
        date1.setTime(131441200l);
        System.out.println("设置时间：" + date);
        System.out.println(date.after(date1));
        System.out.println(date.before(date1));
        System.out.println(date.equals(date1));

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy--MM-dd HH:mm:ss");
        System.out.println(sdf.toPattern());
        System.out.println(sdf.format(date));
        try {
//            将字符串转换成日期
            Date date2 = sdf.parse("2018--12--03 23:22:12");
            System.out.println(date2);
//            将日期转换成字符串
            String strDate = sdf.format(date2);
            System.out.println(strDate);
        } catch (ParseException e) {
            e.printStackTrace();

        }

        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        System.out.println(calendar.get(Calendar.YEAR));
        System.out.println(calendar.get(Calendar.MONTH) + 1);
        System.out.println(calendar.get(Calendar.DATE));

    }
}
